package com.st.shopadmin.controller;

import com.st.shopadmin.annotation.LoginAccess;
import com.st.shopadmin.common.ServerResponse;
import com.st.shopadmin.pojo.MessageContent;
import com.st.shopadmin.service.SystemNoticeService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/manage/message/")
public class SystemNoticeController {
    @Autowired
    private SystemNoticeService systemNoticeService;
    @RequestMapping("/to_message.do")
    public String table()  {
        return "message/list";
    }


    @RequestMapping("lists.do")
    @ResponseBody
    @LoginAccess
    public ServerResponse getLists(HttpServletRequest httpServletRequest, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
        ServerResponse<List> serverResponse = systemNoticeService.getLists(pageNum,pageSize);
        serverResponse.setTotal(serverResponse.getData().size());
        return serverResponse;
    }

    @RequestMapping("page.do")
    @ResponseBody
    @LoginAccess
    public ServerResponse page(HttpServletRequest httpServletRequest, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
        return systemNoticeService.page(pageNum,pageSize);
    }

    @RequestMapping("add_message.do")
    @ResponseBody
    @LoginAccess
    public ServerResponse addMessage(HttpServletRequest httpServletRequest,MessageContent messageContent){
        return systemNoticeService.addMessage(messageContent);
    }

    @RequestMapping("update_message.do")
    @ResponseBody
    @LoginAccess
    public ServerResponse updateMessage(HttpServletRequest httpServletRequest,String title ,String content,Long messageId){
        return systemNoticeService.updateMessage(title ,content,messageId);
    }

    @RequestMapping("detail_message.do")
    @ResponseBody
    @LoginAccess
    public ServerResponse detailMessage(HttpServletRequest httpServletRequest,Long messageId){
        return systemNoticeService.detailMessage(messageId);
    }






}
